//
//  PhotoDetailTwoViewController.m
//  艾听歌
//
//  Created by dllo on 16/5/31.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "PhotoDetailTwoViewController.h"
#import "HotPlayCell.h"
#import "PlayMusicModel.h"
#import "SongListModel.h"
#import "MusicPlyController.h"
#import "UrlListModel.h"

@interface PhotoDetailTwoViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *titleArray;
@property (nonatomic, strong) SongListModel *songModel;
@property (nonatomic, strong) NSMutableArray *MusicArray;
@property (nonatomic, strong) UIButton *LoveButton;
@property (nonatomic, copy) NSString *NameString;

@property (nonatomic, copy) NSString *Name;

@end

@implementation PhotoDetailTwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFF6EB4,0x9C9C9C);
     self.navigationController.navigationBar.dk_barTintColorPicker = DKColorPickerWithRGB(0xFF6EB4,0x9C9C9C);
    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    
    //数组初始化
    self.titleArray = [NSMutableArray array];
    self.MusicArray = [NSMutableArray array];
    
    //网络请求,
    [self getdata];
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 104) style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200)];
    image.backgroundColor = [UIColor blackColor];
    self.tableView.tableHeaderView = image;
    [self.view addSubview:self.tableView];
    //给照片传值
    [image sd_setImageWithURL:[NSURL URLWithString:self.detailsModel.picUrl]];
    
    [self.tableView registerClass:[HotPlayCell class] forCellReuseIdentifier:@"cell"];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"kong"];
    
}

- (void)getdata
{//309093718
    
    NSDictionary *action = self.detailsModel.action;
    NSString *value = [action objectForKey:@"value"] ;
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *str = [NSString stringWithFormat:@"http://api.songlist.ttpod.com/songlists/%@?app=ttpod&v=v9.0.1.2016050614&user_id=0&mid=iPhone7%%2C2&f=f320&s=s310&imsi=&hid=&splus=9.3.1&active=1&net=2&openudid=5e6106cc8d5bcf35f60a2997c79a00bb5a7c631f&idfa=ABDADD65-0877-4840-B14F-DFC8D1114AB0&utdid=VzR0dwnWYs8DANbYJ8SsFzOU&alf=(null)&bundle_id=com.ttpod.music&latitude=-1&longtitude=-1&access_token=(null)&vc=9000100", value];
    [manager GET:str parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        

        PlayMusicModel *bigModel = [[PlayMusicModel alloc]init];
        [bigModel setValuesForKeysWithDictionary:responseObject];
        
        NSMutableArray *song = bigModel.songs;
        for (SongListModel *smallModel in song) {
            
            [self.titleArray addObject:smallModel];
        
//            NSLog(@"%@", smallModel.urlList);
        }
        
        
        
        
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"error==%@", error);
    }];
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.titleArray.count;
}
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    HotPlayCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
//    
//   
//    self.songModel = [self.titleArray objectAtIndex:indexPath.row];
//    cell.number.text = [NSString stringWithFormat:@"%ld",indexPath.row + 1];
//    cell.singerName.text = self.songModel.name;
//    cell.desNmae.text = [NSString stringWithFormat:@"%@--%@",self.songModel.singerName, self.songModel.albumName];
//    self.NameString = self.songModel.name;
//    cell.dk_backgroundColorPicker = DKColorPickerWithRGB(0XFFFFFF, 0X9C9C9C);
//    cell.model = _songModel;
//    
//    return cell;
//}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.titleArray.count == 0) {
        UITableViewCell * cell  = [tableView dequeueReusableCellWithIdentifier:@"kong"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"kong"];
            
        }
        return cell;
    }
    HotPlayCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x9c9c9c);
    SongListModel *model = self.titleArray[indexPath.row];
    
    cell.number.text = [NSString stringWithFormat:@"%ld",indexPath.row + 1];
    cell.singerName.text = model.name;
    cell.desNmae.text = model.singerName;
    
    return cell;
}

//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    MusicPlyController *MusicPlay = [MusicPlyController musicplyVC];
//    
//    NSMutableArray *newArray = [NSMutableArray array];
//    
//    for (SongListModel *listModel in self.titleArray) {
//        
//        UrlListModel *urlModel = [listModel.urlList firstObject];
//        
//        [newArray addObject:urlModel.url];
//    }
//    
//    
//    MusicPlay.MusicArray = [NSMutableArray arrayWithArray:newArray];
//    MusicPlay.index = indexPath.row;
//    NSLog(@"%@", newArray);
//    
//    [self presentViewController:MusicPlay animated:YES completion:^{
//        
//        
//    }];
//    
//    
//}


//cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return 80;
}

@end
